import Vue from 'vue'
import Router from 'vue-router'



// 解决ElementUI导航栏中的vue-router在3.0版本以上重复点菜单报错问题
const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}
//引入组件
import Home from "../views/Home.vue"
import Search from "../components/Search.vue"
// const Goods = ()=>{/*webpackChunkName:"goods"*/ '../views/Goods.vue'}
import Goods from '../views/Goods.vue'
import Info from "../components/goods/Info.vue"
import Foods from '../views/Foods.vue'
import News from '../views/News.vue'
import Mycenter from "../views/Mycenter"
import Order from '../views/Order.vue'
import Login from '../components/Login.vue'
import Details from '../views/Details.vue'
import Feed from '../components/news/Feed.vue'
import Account from "../components/mycenter/Account.vue"
import Address from "../components/mycenter/Address.vue"
import Sefaty from "../components/mycenter/Sefaty.vue"
import Shopcar from "../views/Shopcar.vue"
import Fooddetails from "../views/Fooddetails"
import Purchase from "../views/Purchase"
import Purconfirm from "../components/purchase/Purconfirm.vue"
Vue.use(Router)

const router = new Router({
  mode: 'history',
  routes:[
    // 配置路由规则
    // 重定向
    {
      path:'/',
      redirect:'/home'
    },
   {
    path:'/home' ,
    name:"Home",
    component:Home
   },
   {
    path:'/search' ,
    name:"Search",
    component:Search
   },
   {
    path:'/goods' ,
    name:"Goods",
    component:Goods,
    children:[
      {
        path:'info',
        name:'Info',
        component:Info
      }],
    },
    {
      path:'/foods' ,
      name:'Foods',
      component:Foods,
      children:[
        {
          path:'info',
          name:'Info',
          component:Info
        },
       
      ]
    },
    {
      path:'/news' ,
      redirect:'/news/feed',
      component:News,
      children:[
        {
          path:'feed',
          name:"Feed",
          component:Feed,
        }
        
      ]
    },
    {
      path:'/order',
      name:"Order",
      component:Order,
      meta: {
        requireAuth: true // 需要验证登录状态
      }
    },
    {
     path:'/mycenter' ,
    //  redirect:'/mycenter/account',
    component:Mycenter,
    meta: {
      requireAuth: true // 需要验证登录状态
    },
    children:[
      {
        path:'account',
        name:"Account",
        component:Account,
        
      },
      {
        path:'address',
        name:"Address",
        component:Address,
      },
      {
        path:'sefaty',
        name:"Sefaty",
        component:Sefaty,
      },
    ]
     },
     {
      path:'/details' ,
      name:"Details",
      component:Details
     },
     {
      path:'/fooddetails' ,
      name:"Fooddetails",
      component:Fooddetails
     },
     {
      path:'/purchase' ,
      redirect:'/purchase/purconfirm',
      component:Purchase,
      children:[
        {
          path:'purconfirm',
          name:'Purconfirm',
          component:Purconfirm,
        },
      ]
     },
     {
      path:'/login' ,
      name:"Login",
      component:Login
     },
     {
      path:'/shopcar' ,
      name:"Shopcar",
      component:Shopcar,
      meta: {
        requireAuth: true // 需要验证登录状态
      }
      },
    
  
],
// scrollBehavior () {
//   return { x: 0, y: 0 }
// }
});
//挂在路由导航守卫
// router.beforeEach((to,from,next) =>{
//   // 首先判断是不是重登录页面来
//   if(to.path === '/login')return next();
//   //获取token，判断是否是有效token
//   const isToken = window.localStorage.getItem("token")
//   if(!isToken)  return next('/login')
//   next()
// })
export default router